<?php

Yii::import('application.models._base.BaseMessageScreen');

class MessageScreen extends BaseMessageScreen
{
	public static function model($className=__CLASS__) {
		return parent::model($className);
	}
    public function meTohe($user_id,$friend_id){
        $data = $this->find('user_id=:user_id and friend_id=:friend_id',array(':user_id'=>$user_id,':friend_id'=>$friend_id));
        return $data;
    }
    public function heTome($user_id,$friend_id){
        $data = $this->find('user_id=:user_id and friend_id=:friend_id',array(':user_id'=>$friend_id,':friend_id'=>$user_id));
        return $data;
    }
    public function getAllScreen($user_id){
        $db = Yii::app()->db->createCommand();
        $info = $db->select('u.id,u.nick_name,u.domain,u.avatar_status,u.avatar_public')
            ->from('{{message_screen}} ms')
            ->where('ms.user_id=:user_id AND ms.relation_status=:relation_status',array(':user_id'=>$user_id,':relation_status'=>0))
            ->leftJoin('{{user}} u','ms.friend_id=u.id')
            ->order('ms.id desc')
            ->queryAll();
        return $info;
    }
    /**
     * @param $friend_id  你查看这个的用户的id
     * @param $user_id  我的id
     * @return bool
     * 查看这个用户 对于你的状态 这里   user_id = $friend_id
     */
    public function getRelationship($friend_id,$user_id){
        //对方对你的关系
        $data = $this->heTome($user_id,$friend_id);
        //你对他的关系
        $data1 = $this->meTohe($user_id,$friend_id);
        $info = array();
        $info['hetome'] = 1;
        $info['metohe'] = 1;
        if($data){
            if($data->relation_status == 0){
                $info['hetome'] = 0;
            }
        }
        if($data1){
            if($data1->relation_status == 0){
                $info['metohe'] = 0;
            }
        }
        return $info;
    }

}